package ThreadBasic.other;

import java.util.concurrent.CyclicBarrier;

/**
 * @author yyh
 * @create 2020-11-10 8:41
 */
public class CyclicBarrierDemo {

    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7,() -> {
            System.out.println("成功");
        });

        for (int i = 1; i < 8; i++) {
            final int temp = i;
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName()+"收集： "+ temp);
                try{
                    cyclicBarrier.await();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
